const SerialPort = require("serialport");
const { SERIAL_PORT } = require('../config/index.json');

//打开串口
const serialport = new SerialPort(SERIAL_PORT, {
    baudRate: 9600,
    autoOpen: true
})

//串口信息
interface port{
    path: string,
    manufacturer: string,
    serialNumber:any,
    pnpId: string,
    locationId: any,
    vendorId: any,
    productId: any,
}
// //连接串口开始监听
// serialport.on('data', function (data:string) {
//     console.log('data received:' + data);
//     portdata = data;
// })
//错误监听
serialport.on('error', function (error:string) {
    console.log('error:' + error);
})

SerialPort.list().then((res:Array<port>) => {
    console.log('可用串口信息', res);
}).catch((error:any) => {
    console.log(error);
})

module.exports = serialport;